<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	template="/templates/loggedTemplate.xhtml">

	<f:metadata>
		<f:event type="preRenderView"
			listener="#{hospitalBean.initConversation}" />
	</f:metadata>

	<ui:define name="content">
		<h1 class="formTitle ui-widget-header ui-corner-all">#{msg['hospital.titulo.cadastro']}</h1>

		<h:form id="hospitalForm">
		
			<p:growl id="messages" />	
		
			<p:panelGrid columns="2" id="panel">
			
				#{msg['hospital.nome']}
				<p:inputText value="#{hospitalBean.entidade.nome}" id="nome"
					label="#{msg['hospital.nome']}" />
				
				#{msg['hospital.enderecos']}
				<p:panel style="border: 0px;">
					<p:commandButton value="#{msg['botao.adicionar']}" oncomplete="dlg1.show()"
						action="#{hospitalBean.incluirEndereco}" immediate="true" />
					<p:dataTable id="enderecos" var="endereco"
						value="#{hospitalBean.entidade.enderecos}">
						<p:column headerText="#{msg['endereco.identificador']}">
							<h:outputText value="#{endereco.identificador}" />
						</p:column>
						<p:column headerText="#{msg['endereco.logradouro']}">
							<h:outputText value="#{endereco.logradouro}" />
						</p:column>
						<p:column headerText="#{msg['endereco.numero']}">
							<h:outputText value="#{endereco.numero}" />
						</p:column>
						<p:column headerText="#{msg['endereco.complemento']}">
							<h:outputText value="#{endereco.complemento}" />
						</p:column>
					</p:dataTable>
				</p:panel>

			</p:panelGrid>
			
			<div id="buttons" class="ui-widget ui-widget-header">
				<p:commandButton value="#{msg['botao.salvar']}"
					action="#{hospitalBean.salvar}" update="hospitalForm" ajax="false" />
				<p:commandButton value="#{msg['botao.cancelar']}"
					action="#{hospitalBean.cancelar}" immediate="true" />
			</div>
			
			<p:dialog id="basicDialog" header="#{msg['hospital.enderecos']}"
				widgetVar="dlg1">
				<p:panelGrid columns="2">
					<f:facet name="header">  
				        #{msg['hospital.enderecos']}  
				    </f:facet>

					<p:inputText value="#{hospitalBean.endereco.identificador}"
						id="identificador" label="#{msg['endereco.identificador']}" />
					
					<p:inputText value="#{hospitalBean.endereco.logradouro}"
						id="logradouro" label="#{msg['endereco.logradouro']}" />

					<f:facet name="footer">
						<p:commandButton id="salvarEndereco" value="#{msg['botao.salvar']}" update="enderecos"
							oncomplete="dlg1.hide()" action="#{hospitalBean.salvarEndereco}" icon="ui-icon-check" />
						<p:commandButton id="cancelarEndereco" value="#{msg['botao.cancelar']}"
							onclick="dlg1.hide()" />
					</f:facet>
				</p:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
	
	
</ui:composition>
